{block name="main"}
<!-- page -->
<div class="mb-20">
    <a href="#" class="btn btn-primary add_tag"><i class="icon icon-add1"></i> 添加标签</a>
</div>
<table class="table v-table table-auto-center">
    <thead>
    <tr>
        <th>标签名称</th>
        <th class="col-md-2 pr-14 operationLeft">操作</th>
    </tr>
    </thead>
    <!--<tbody id="coupon_type_list">
    </tbody>-->
    <tbody id="custom_form_list">
    {if $custom_tags}
    {foreach $custom_tags as $tag}
    <tr>
        <td>
            <input type="hidden" name="id" value="{$tag.id}">
            <input type="text" class="form-control tag_Name" data_c_id="{$tag.id}" name="tagName"  value="{$tag.tag_name}">
        </td>
        <td class="fs-0 operationLeft">
            <a href="javascript:;" data-coupon-type-id="{$tag.id}" class="btn-operation text-red1 del">删除</a>
        </td>
    </tr>
    {/foreach}
    {else}
    <tr><td class="h-200" colspan="4">暂无符合条件的数据记录</td></tr>
    {/if}
    <tr class="tr_tag_name hidden" >
        <td>
            <input type="text" class="form-control tagName" name="tagName" value="">
        </td>
        <td class="fs-0 operationLeft">
            <a href="javascript:;" data-coupon-type-id="{$tag.id}" class="btn-operation text-red1 remove_del">删除</a>
        </td>
    </tr>
    </tbody>

</table>
<input type="hidden" id="page_index">
<nav aria-label="Page navigation" class="clearfix">
    <ul id="page" class="pagination pull-right"></ul>
</nav>

<!-- page end -->
{/block}
{block name="script"}
<script id="shop_curr_list" type="text/html">

    <tr>
        <td>
            <input type="text" class="form-control tagName" name="tagName" value="">
        </td>
        <td class="fs-0 operationLeft">
            <a href="javascript:;" data-coupon-type-id="{$tag.id}" class="btn-operation text-red1 del">删除</a>
        </td>
    </tr>

</script>

<script>
    

    require(['util'], function (util) {
        $('.add_tag').click(function () {
            $('.tr_tag_name').removeClass('hidden');
        });
        $('.remove_del').click(function () {
            $('.tr_tag_name').addClass('hidden');
        });
        $('body').on('blur','.tagName',function () {
            var _this=$(this);
            var val = _this.val();
            if(val==''){
                _this.addClass('addBoder');
                util.message('请填写标签名称','danger');
                return false;
            }else{
                _this.removeClass('addBoder');
            }

            $.ajax({
                type: "post",
                url: "{$addCustomFormTagUrl}",
                sync: true,
                data: {
                    "data": val,
                },
                success: function (data) {
                    if (data["code"] > 0) {
                        util.message(data["message"], 'success', "{:__URL('ADDONS_MAINcustomFormTagList')}");
                    } else {
                        util.message(data["message"], 'danger');
                    }
                }
            });
        });

        $('#custom_form_list').on('click', '.del', function () {
            var custom_form_id = $(this).attr('data-coupon-type-id');
            util.alert('确定删除？', function () {
                $.ajax({
                    type: "post",
                    url: "{$deleteCustomFormTagUrl}",
                    data: {"id": custom_form_id},
                    dataType: "json",
                    success: function (data) {
                        if (data["code"] > 0) {
                            util.message(data["message"], 'success', "{:__URL('ADDONS_MAINcustomFormTagList')}");
                        } else {
                            util.message(data["message"], 'danger');
                        }
                    }
                })
            })
        });

        var tag_name = '';
        $('.tag_Name').click(function () {
            var id = $(this).attr('data_c_id');
            tag_name = $(this).val();
        });
        $('.tag_Name').blur(function () {
            var id = $(this).attr('data_c_id');
            if ($(this).val() != tag_name) {
                $.ajax({
                    type: "post",
                    url: "{$addCustomFormTagUrl}",
                    async: true,
                    data: {
                        "data": $(this).val(),
                        "id": id,
                    },
                    success: function (data) {
                        if (data["code"] > 0) {
                            util.message(data["message"], 'success', "{:__URL('ADDONS_MAINcustomFormTagList')}");
                        } else {
                            util.message(data["message"], 'danger');
                        }
                    }
                });
            }
        });

        
    });


</script>
{/block}
